home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / JForth / Extras / SysGen / case < prev    next >
Encoding:
Text File  |  1992-01-02  |  875 b   |  48 lines

  1. \ ================= CASE STATEMENT ===============
  2. \
  3. \ PLB MOD: 8/31/90 Added RANGEOF and ?OF
  4. \ PLB MOD: 8/1/91 Use [compile] IF in ?OF, c/[]/[compile]/
  5. \ 00001 PLB 12/31/91 Use OF_FLAG to check for missing ENDOF
  6.  
  7. 6 CONSTANT OF_FLAG
  8.  
  9. : CASE ( -- , start case statement )
  10.     ?COMP CSP @ !CSP IF_FLAG
  11. ; IMMEDIATE
  12.  
  13. : ?OF  ( flag -comp- flag , n flag -run- n | )
  14.     IF_FLAG ?PAIRS
  15.     [compile] IF
  16.     compile drop
  17.     drop of_flag  \ for ENDOF 00001
  18. ; IMMEDIATE
  19.  
  20. : OF ( -- )
  21.     compile over compile = 
  22.     [compile] ?of
  23. ; IMMEDIATE
  24.  
  25. : (RANGEOF?)  ( n lo hi -- n flag )
  26.     >r >r dup r> r> within?
  27. ;
  28.  
  29. : RANGEOF ( -- )
  30.     compile (rangeof?)
  31.     [compile] ?OF
  32. ; IMMEDIATE
  33.  
  34. : ENDOF
  35.     of_flag ?pairs \ 00001
  36.     if_flag
  37.     [compile] ELSE
  38. ; IMMEDIATE
  39.  
  40. : ENDCASE
  41.     IF_FLAG ?PAIRS
  42.     compile drop
  43.     BEGIN sp@ csp @ = 0=
  44.     WHILE IF_FLAG [compile] then
  45.     REPEAT
  46.     csp !
  47. ; IMMEDIATE
  48.